//
//  NSString+Category_WPP.m
//  BaseProject
//
//  Created by mac on 2020/12/5.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "NSString+Category_WPP.h"

@implementation NSString (Category_WPP)
#pragma mark - 计算宽高
- (CGSize)sizeWithFont:(UIFont *)font
{
    CGSize theSize;
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    theSize = [self sizeWithAttributes:attributes];
    // 向上取整
    theSize.width = ceil(theSize.width);
    theSize.height = ceil(theSize.height);
    return theSize;
}
- (CGSize)sizeWithLimitSize:(CGSize)limitSize andFont:(UIFont *)font
{
    CGSize theSize;
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    CGRect rect = [self boundingRectWithSize:limitSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil];
    theSize.width = ceil(rect.size.width);
    theSize.height = ceil(rect.size.height);
    return theSize;
}
- (CGSize)sizeWithMaxWidth:(CGFloat)width andFont:(UIFont *)font
{
    return [self sizeWithLimitSize:CGSizeMake(width, MAXFLOAT) andFont:font];
}
#pragma mark - 验证转换
- (NSURL *)wppURL
{
    return [NSURL URLWithString:self];
}

@end
